package com.ssy.lingxi.platform.manage.controller.content;

import com.ssy.lingxi.common.controller.BaseController;
import com.ssy.lingxi.common.response.PageData;
import com.ssy.lingxi.common.response.Wrapper;
import com.ssy.lingxi.platform.manage.entity.content.MemberAdvert;
import com.ssy.lingxi.platform.manage.model.request.common.CommonIdRequest;
import com.ssy.lingxi.platform.manage.model.request.common.CommonStatusRequest;
import com.ssy.lingxi.platform.manage.model.request.content.MemberAdvertPageRequest;
import com.ssy.lingxi.platform.manage.model.request.content.MemberAdvertQueryRequest;
import com.ssy.lingxi.platform.manage.model.request.content.MemberAdvertRequest;
import com.ssy.lingxi.platform.manage.service.content.IMemberAdvertService;
import io.swagger.annotations.ApiOperation;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @menu 内容能力 - 广告管理
 * @author hsl
 * @version 2.0.0
 * @date 2022/03/11
 */
@RestController
@RequestMapping("/manage/memberAdvert")
public class MemberAdvertController extends BaseController {

    @Resource
    private IMemberAdvertService memberAdvertService;

    /**
     * 能力中心-查询广告分页列表
     * @param request 分页查询参数
     * @return 广告分页列表
     */
    @GetMapping("/page")
    public Wrapper<PageData<MemberAdvert>> page(MemberAdvertPageRequest request) {

        return memberAdvertService.page(request,getSysUser());
    }

    /**
     * 能力中心-查看广告详情
     * @param request 广告id请求传参
     * @return 广告详情
     */
    @GetMapping(value = "/get")
    public Wrapper<MemberAdvert> get(@Validated CommonIdRequest request) {
        return memberAdvertService.get(request);
    }

    /**
     * 能力中心-新增广告
     * @param request 新增广告传参
     * @return 操作成功默认信息
     */
    @ApiOperation(value = "新增")
    @PostMapping(value = "/add")
    public Wrapper<Void> add(@RequestBody @Validated({MemberAdvertRequest.Add.class}) MemberAdvertRequest request) {
        return memberAdvertService.add(request, getSysUser());
    }

    /**
     * 能力中心-修改广告
     * @param request 更新广告传参
     * @return 操作成功默认信息
     */
    @PostMapping(value = "/update")
    public Wrapper<Void> update(@RequestBody @Validated({MemberAdvertRequest.Update.class}) MemberAdvertRequest request) {
        return memberAdvertService.update(request, getSysUser());
    }

    /**
     * 能力中心-上下架广告
     * @param request 更新广告状态传参
     * @return 操作成功默认信息
     */
    @PostMapping(value = "/updateStatus")
    public Wrapper<Void> updateStatus(@RequestBody @Validated ({CommonStatusRequest.Shelf.class}) CommonStatusRequest request) {
        return memberAdvertService.updateStatus(request, getSysUser());
    }

    /**
     * 能力中心-删除广告
     * @param request 广告id请求传参
     * @return 操作成功默认信息
     */
    @ApiOperation(value = "删除")
    @PostMapping(value = "/delete")
    public Wrapper<Void> delete(@RequestBody @Validated CommonIdRequest request) {
        return memberAdvertService.delete(request, getSysUser());
    }

    /**
     * 商城-获取广告
     * @param request 查询广告传参
     * @return 广告列表
     */
    @GetMapping("/findAllByColumnType")
    public Wrapper<List<MemberAdvert>> findAllByColumnType(MemberAdvertQueryRequest request) {
        return memberAdvertService.findAllByColumnType(request);
    }
}
